package com.lxg.ai.config;


import com.lxg.ai.properties.BgeM3EmbeddingProperties;
import com.lxg.ai.properties.QdrantStoreProperties;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.model.openai.OpenAiEmbeddingModel;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class EmbeddingConfig {


    @Bean
    public QdrantClient qdrantClient(@Autowired QdrantStoreProperties qdrantStoreProperties) {
        QdrantGrpcClient.Builder grpcClientBuilder = QdrantGrpcClient.newBuilder(qdrantStoreProperties.getHost(), qdrantStoreProperties.getPort(), qdrantStoreProperties.getUseTransportLayerSecurity());
        return new QdrantClient(grpcClientBuilder.build());
    }

    @Bean
    public EmbeddingModel embeddingModel(@Autowired BgeM3EmbeddingProperties bgeM3EmbeddingProperties) {
        return OpenAiEmbeddingModel.builder()
                .apiKey(bgeM3EmbeddingProperties.getApiKey())
                .modelName(bgeM3EmbeddingProperties.getModel())
                .baseUrl(bgeM3EmbeddingProperties.getBaseUrl())
                .build();
    }

}
